public class Leet121 {
    public int maxProfit(int[] prices) {
        int min = Integer.MAX_VALUE,max = Integer.MIN_VALUE;
        for (int i = 0; i < prices.length; i++) {
            if (min>prices[i])
            min = prices[i];
            if (max<prices[i]-min)
            max = prices[i]-min;
        }
        return max;
    }
}
